﻿using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using System;
using System.Collections.Generic;
using System.Text;
using DataService.Office.WordMain;

namespace UnitTest.Word
{
    public class TestWord
    {
        public void TestOutputWord(string wordFullPath)
        {

            string str = @"";
            IXmlPackageBussiness packageBussiness = new XmlPackageBussiness();
            WordprocessingDocument wd = null;
            if (File.Exists(wordFullPath))
            {
                wd = packageBussiness.OpenDocumentPart(wordFullPath);

            }
            else
            {
                wd = packageBussiness. CreateDocumentPart(wordFullPath);
            }
            MainDocumentPart md = wd.MainDocumentPart;
            Body body = md.Document.Body;

           var currentElement = body.AppendChild<Paragraph>(new Paragraph());
            Run titleRun = currentElement.AppendChild(new Run());
            Text runtxt = new Text();
            runtxt.Text = str;
           
            titleRun.Append(runtxt);

            md.Document.Save();

            wd.Dispose();
        }
    }
}
